﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Collections.ObjectModel;

namespace WPFInterface.ViewModel
{
    public class DeletePatientViewModel : BaseViewModel
    {
        private List<string> _roleList;
        private bool _closeSignal;
        private ICommand _deleteCommand;
        private Dbo.Patient _patient;
        private ObservableCollection<Dbo.Patient> _listDeletePatients;
        private HomeViewModel hvm;
        private int _patientIndex;

        public int PatientIndex
        {
            get { return _patientIndex; }
            set
            {
                if (_patientIndex != value)
                {
                    _patientIndex = value;
                    OnPropertyChanged("PatientIndex");
                }
            }
        }

        public HomeViewModel Hvm
        {
            get { return hvm; }
            set { hvm = value; }
        }

        public ObservableCollection<Dbo.Patient> ListDeletePatients
        {
            get { return _listDeletePatients; }
            set
            {
                if (_listDeletePatients != value)
                {
                    _listDeletePatients = value;
                    OnPropertyChanged("ListDeletePatients");
                }
            }
        }


        public Dbo.Patient Patient
        {
            get { return _patient; }
            set
            {
                if (_patient != value)
                {
                    _patient = value;
                    OnPropertyChanged("Patient");
                }
            }
        }

        public List<string> RoleList
        {
            get { return _roleList; }
            set { _roleList = value; }
        }

        /// <summary>
        /// indique si on doit fermer la fenêtre ou non
        /// </summary>
        public bool CloseSignal
        {
            get { return _closeSignal; }
            set
            {
                if (_closeSignal != value)
                {
                    _closeSignal = value;
                    OnPropertyChanged("CloseSignal");
                }
            }
        }

        /// <summary>
        /// command pour s'authentifier
        /// </summary>
        public ICommand DeleteCommand
        {
            get { return _deleteCommand; }
            set { _deleteCommand = value; }
        }

        public DeletePatientViewModel()
        {
            ServicePatient.ServicePatientClient patients = new ServicePatient.ServicePatientClient();
            ListDeletePatients = new ObservableCollection<Dbo.Patient>(patients.GetListPatient());
            _deleteCommand = new RelayCommand(param => DeleteAccess(), param => true);
        }

        private void DeleteAccess()
        {
            ServicePatient.ServicePatientClient deletepatient = new ServicePatient.ServicePatientClient();
            
            if (Patient != null)
            {
                Hvm.ListPatients.RemoveAt(PatientIndex);
                deletepatient.DeletePatient(Patient.Id);
                
            }
            this.CloseSignal = true;
        }
    }
}
